import axios from "../utils/http";

const GoodsStore = {
    namespaced:true,
    state:()=>({
        goods_list:[],
        count:0
    }),
    mutations:{
        GoodsMutations(state,list){
            state.goods_list = list
        },
        GoodsCountMutations(state,count){
            state.count = count
        }
    },
    actions:{
        GoodsActions(context,page = { page: 1, size: 5 }){
            var url = "/api/goodslist?page=" + page.page + "&size=" + page.size
            axios.get(url).then(
                res=>{
                    if (res.code === 200) {
                        console.log(res);
                        context.commit("GoodsMutations", res.list)
                    }
                }
            )
        },
        GoodsCountActions(context){
            axios.get("/api/goodscount").then(
                res=>{
                    if(res.code === 200){
                        context.commit('GoodsCountMutations',res.list[0].total)
                    }
                }
            )
        }
    }
}

export default GoodsStore